package com.site.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.site.base.dao.Page;
import com.site.base.service.BaseService;
import com.site.dao.GoodContentDao;
import com.site.dao.HuntContentDao;
import com.site.dao.HuntSiteDao;
import com.site.dao.PublishedContentDao;
import com.site.dao.SiteDomainDao;
import com.site.dao.SpinContentDao;
import com.site.dao.TmpHuntContentDao;
import com.site.entity.GoodContent;
import com.site.entity.HuntContent;
import com.site.entity.HuntSite;
import com.site.entity.TmpHuntContent;

@Service
public class SiteService extends BaseService{
	
	@Autowired
	private HuntContentDao huntContentDao = null;
	
	@Autowired
	private GoodContentDao goodContentDao = null;
	
	@Autowired
	private TmpHuntContentDao tmpHuntContentDao = null;
	
	@Autowired
	private HuntSiteDao huntSiteDao = null;
	
	@Autowired
	private PublishedContentDao publishedContentDao = null;
	
	@Autowired
	private SiteDomainDao siteDomainDao = null;
	
	@Autowired
	private SpinContentDao spinContentDao = null;
	
	public SiteService(){
		init();
	}
	
	private void init(){
		
	}
	
	public List<HuntSite> queryHuntSite(){
		return huntSiteDao.findAll();
	}
	
	public List<GoodContent> queryGoodContent(){
		return goodContentDao.findAll();
	}
	
	/**
	 * 查询采集的数据
	 * @return
	 */
	public List<TmpHuntContent> queryTmpHuntContent(int count){
		String hql = "from TmpHuntContent";
		Page<TmpHuntContent> page = new Page<TmpHuntContent>();
		page.setPageNo(1);
		page.setPageSize(count);
		Map<String, Object> dataMap = new HashMap<String, Object>();
		page = tmpHuntContentDao.find(page, hql, dataMap);
		return page.getResult();
	}
	
	/**
	 * 保存合格的采集数据
	 * @param list
	 */
	public void saveHuntContent(List<HuntContent> list){
		if(list == null || list.isEmpty()){
			return;
		}
		huntContentDao.saveBatch(list);
	}
	
	
	/**
	 * 更新校验失败的采集文章的校验位
	 * @param list
	 */
	public void updateTmpHuntContentCheck(List<TmpHuntContent> list){
		if(list == null || list.isEmpty()){
			return;
		}
		StringBuffer hql = new StringBuffer("update TmpHuntContent t set t.checkContent=? where t.id in(");
		for(int i=0; i<list.size() - 1; i++){
			hql.append("?,");
		}
		hql.append("?)");
		Object[] data = new Object[1 + list.size()];
		data[0] = "F";
		for(int i=0; i< list.size(); i++){
			data[i+1] = list.get(i).getId(); 
		}
 
		huntContentDao.execute(hql.toString(), data);
	}

	public HuntContentDao getHuntContentDao() {
		return huntContentDao;
	}

	public void setHuntContentDao(HuntContentDao huntContentDao) {
		this.huntContentDao = huntContentDao;
	}

	public GoodContentDao getGoodContentDao() {
		return goodContentDao;
	}

	public void setGoodContentDao(GoodContentDao goodContentDao) {
		this.goodContentDao = goodContentDao;
	}

	 

	public TmpHuntContentDao getTmpHuntContentDao() {
		return tmpHuntContentDao;
	}

	public void setTmpHuntContentDao(TmpHuntContentDao tmpHuntContentDao) {
		this.tmpHuntContentDao = tmpHuntContentDao;
	}

	public HuntSiteDao getHuntSiteDao() {
		return huntSiteDao;
	}

	public void setHuntSiteDao(HuntSiteDao huntSiteDao) {
		this.huntSiteDao = huntSiteDao;
	}

	public PublishedContentDao getPublishedContentDao() {
		return publishedContentDao;
	}

	public void setPublishedContentDao(PublishedContentDao publishedContentDao) {
		this.publishedContentDao = publishedContentDao;
	}

	public SiteDomainDao getSiteDomainDao() {
		return siteDomainDao;
	}

	public void setSiteDomainDao(SiteDomainDao siteDomainDao) {
		this.siteDomainDao = siteDomainDao;
	}

	public SpinContentDao getSpinContentDao() {
		return spinContentDao;
	}

	public void setSpinContentDao(SpinContentDao spinContentDao) {
		this.spinContentDao = spinContentDao;
	}

}
